package com.baozhun.mall.common.network

import android.os.Build
import com.baozhun.mall.common.util.CacheUtil
import com.baozhun.mall.common.util.DeviceUtil
import com.blankj.utilcode.util.AppUtils
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 * 自定义头部参数拦截器，传入heads
 */
class MyHeadInterceptor : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        if (CacheUtil.isLogin()) {
            builder.addHeader("authorization", CacheUtil.getUser()?.token)
        }
        builder.addHeader("os", "android")
        builder.addHeader("lang", "zh-CN")  //zh-cn or en
        builder.addHeader("devices", DeviceUtil.getDeviceId())
        builder.addHeader("osversion", Build.VERSION.RELEASE)
        builder.addHeader("version", AppUtils.getAppVersionName())
        return chain.proceed(builder.build())
    }

}